package cn.ultrarisk.scadmin.manager.biz.solr.dto;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * CollectionUpdater
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/6/7
 * @since V1.0
 */
public class CollectionUpdater implements Serializable {
    private static final long serialVersionUID = -3130981214786152923L;

    private String docType;
    private String doc;
    private Boolean commit;
    private Boolean overwrite;

    public String getDocType() {
        return docType;
    }

    public void setDocType(String docType) {
        this.docType = docType;
    }

    public String getDoc() {
        return doc;
    }

    public void setDoc(String doc) {
        this.doc = doc;
    }

    public Boolean getCommit() {
        return commit;
    }

    public void setCommit(Boolean commit) {
        this.commit = commit;
    }

    public Boolean getOverwrite() {
        return overwrite;
    }

    public void setOverwrite(Boolean overwrite) {
        this.overwrite = overwrite;
    }

    public String getContentType() {
        return "json".equals(docType) ? "application/json" : "text/xml";
    }

    public Map<String, Object> getParams() {
        Map<String, Object> querys = new LinkedHashMap<String, Object>();

        querys.put("commit", commit);
        querys.put("overwrite", overwrite);
        querys.put("wt", "json");
        querys.put("indent", true);
        return querys;
    }

    public String getPostData() {
        if ("json".equals(docType)) {
            return "{\"add\":{\"doc\":" + doc + "}}";
        }
        return "<add>" + doc + "</add>";
    }
}
